package friend

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"practice/config"
	"practice/internal/model/dao"
)

type Friends struct {
	Mobile string `form:"mobile" json:"mobile" xml:"mobile"  binding:"required,mobile"`
	Name   string `form:"name" json:"password" xml:"password"`
	Note   string `form:"note" json:"note" xml:"note"`
}

func DelFriend(c *gin.Context) {
	var json Friends
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	mobile := json.Mobile
	name := json.Name
	note := json.Note
	var friend dao.Friends
	config.DB.Where("mobile=? or name like ? or note like ?", mobile, "%"+name+"%", "%"+note+"%").First(&friend)
	if friend.ID == 0 {
		c.JSON(http.StatusBadRequest, gin.H{"error": "没有该好友"})
		return
	}
	config.DB.Where("mobile=?", mobile).Delete(&friend)
	c.JSON(http.StatusOK, gin.H{
		"msg": "删除好友成功",
	})
}
